<?php

	class object extends root {
	
		private $db;
		private $objTable;
		private $document;
		
		/**
		CONSTRUCTOR
		**/
		public function __construct($table) {
		
			$this->db = new db();
			$this->objTable = $table;
			$this->document = new document();
		
   		}
   		
   		
   		/**
   		FILTER DATA
   		**/
   		public function filter($arr) {
   			
   			$filtered = unserialize(FILTER);
   			
   			while(list($key, $val) = each($filtered)) {
   				unset($arr[$val]);
   			}
   			
   			return $arr;
   		}
   		
   		
   		/**
   		SELECT SINGLE OBJ
   		**/
   		public function selectSingleBy($fields, $conditions = "1", $options = "") {
   			
   			$row = $this->db->selectBy($this->objTable, $fields, $conditions = "1", $options = "");
   			
   			return $row;
   		}
   		
		
		/**
		SELECT SINGLE OBJ BY ID
		**/
		public function selectSingleById($id) {
			
			$row = $this->db->selectById($this->objTable, $id);	
			
			return $row;
		}
		
		
		/**
		SELECT ALL OBJ
		**/
		public function selectAll() {
			
			$row = $this->db->selectAll($this->objTable);
			
			return $row;
		}
		
		
		/**
		INSERT SINGLE OBJ
		**/
		public function insertSingleObj($fields, $files = array()) {
		
			while(list($key, $val) = each($files)) {
			
				if(is_uploaded_file($val['tmp_name'])) {
				
					$this->document->moveToLocal($val['tmp_name']);
					
					$result = $this->document->evaluateDoc($val['type']);
					
					$file_name = $result->upload($val['name']);
					
					$fields[$key] = $file_name;
				
				}
			}
			
			
					
			return $this->db->insert($this->objTable, $this->filter($fields));
			
		}
		
		
		/**
		UPDATE SINGLE OBJ
		**/
		public function updateSingleObj($fields, $conditions, $files = array()) {
		
			while(list($key, $val) = each($files)) {
			
				if(is_uploaded_file($val['tmp_name'])) {
				
					$this->document->moveToLocal($val['tmp_name']);
					
					$result = $this->document->evaluateDoc($val['type']);
					
					$file_name = $result->upload($val['name']);
					
					$fields[$key] = $file_name;
				
				}
			}
						
			return $this->db->update($this->objTable, $fields, $conditions);
		}
		
		
		/**
		DELETE SINGLE OBJ BY ID
		**/
		public function deleteObjById($id) {
			
			return $this->db->delete($this->objTable, $id);
			
		}
		
		
		/**
		DESTRUCTOR
		**/
		public function __destruct() {
		}
	
	}

?>